package net.sansi.v3correctserver.entity.screen;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.sansi.v3correctserver.dto.v3serverapi.V3ServerApiScreenDto;
import net.sansi.v3correctserver.entity.IntPoint;

/**
 * Created by Fang
 * create time : 2024/11/4
 * IDE : IntelliJ IDEA
 * <p>
 * 面板
 */

@EqualsAndHashCode(callSuper = true)
@Api("面板")
@Data
public class Panel extends Rect {
    @ApiModelProperty("面板id")
    private String id;

    @ApiModelProperty("索引")
    private String idx;


    /**
     * 从v3响应内容转换为本地 panel
     *
     * @param panel     面板
     * @param scanBoard 扫描板
     * @return 本地 Panel
     */
    public static Panel of(
            V3ServerApiScreenDto.AllStatusResp.V3Panel panel,
            ScanBoard scanBoard
    ) {
        Panel p = new Panel();
        V3ServerApiScreenDto.AllStatusResp.V3Panel.V3Position position = panel.getPosition();
        p.setIdx(position.getIndex());
        p.setId(position.getPanelID());
        p.setWidth(position.getWidth());
        p.setHeight(position.getHeight());
        p.setStart(new IntPoint(
                position.getX() + scanBoard.getLeft(),
                position.getY() + scanBoard.getTop()
        ));
        return p;
    }
}
